package com.yanqu.road.server.logic.smallgame;

import com.alibaba.fastjson.JSON;
import com.yanqu.road.server.logic.smallgame.stage.GridSwitchStage;
import com.yanqu.road.server.logic.smallgame.stage.WaterSortStage;
import com.yanqu.road.utils.CsvHelper;

import java.io.*;
import java.util.ArrayList;
import java.util.List;

public class StageCSVCreate {
    private static String outPath = "./exportCsv/";

    public static void CreateWaterSortStageConfig(List<WaterSortStage> stages, int colorNum, int emptyNum, int deepNum) {
        List<Object> exportData = new ArrayList<Object>();
        exportData.add("id");
        exportData.add("param");
        exportData.add("stageData");
        exportData.add("answerNum");
        exportData.add("solution");
        List<List<Object>> datalist = new ArrayList<List<Object>>();
        int id = 0;
        for (WaterSortStage stage : stages) {
            List<Object> data = new ArrayList<Object>();
            data.add(++id);
            data.add(stage.getParam());
            data.add(JSON.toJSONString(stage.getColorsConfig()));
            data.add(stage.getAnswerDeep());
            data.add(JSON.toJSONString(stage.getAnswerList()));
            datalist.add(data);
        }

        String fileName = "WaterSortStage_" + String.valueOf(colorNum) + "_" + String.valueOf(emptyNum) + "_" + String.valueOf(deepNum);

        File file = CsvHelper.createCSVFile(exportData, datalist, outPath, fileName);
        System.out.println("创建文件名称：" + file.getName());
    }

    public static void CreateGridSwitchStageConfig(List<GridSwitchStage> stages, int length, int wide, int blankNum, int directionNum, int haveEnd) {
        List<Object> exportData = new ArrayList<Object>();
        exportData.add("id");
        exportData.add("param");
        exportData.add("stageData");
        List<List<Object>> datalist = new ArrayList<List<Object>>();
        int id = 0;
        for (GridSwitchStage stage : stages) {
            List<Object> data = new ArrayList<Object>();
            data.add(++id);
            data.add(stage.getParam());
            data.add(JSON.toJSONString(stage.getAnswerList()));
            datalist.add(data);
        }

        String fileName = "GridSwitchStage_" + String.valueOf(length) + "_" + String.valueOf(wide) +
                "_" + String.valueOf(blankNum) + "_" + String.valueOf(directionNum) + "_" + String.valueOf(haveEnd);

        File file = CsvHelper.createCSVFile(exportData, datalist, outPath, fileName);
        System.out.println("创建文件名称：" + file.getName());
    }
}
